<?php
namespace app\common\helper;
/**
 * Created by PhpStorm.
 * User: zhanghua
 * Date: 2018/9/28
 * Time: 17:48
 */
class StringHelper
{

    public static function strRand($len = 32, $char = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
    {
        if(!is_int($len) || $len < 0) {
            return false;
        }
        $charLen = mb_strlen($char);
        if($len > $charLen){
            return false;
        }

        $string = '';

        for($i = $len; $i > 0; $i--) {
            $string .= $char[mt_rand(0, $charLen - 1)];
        }
        return $string;
    }

}